package com.twu.biblioteca;

/**
 * Created by olga on 7/06/14.
 */
public class TerminalPrintUtility
{
    public static final String WELCOME_MESSAGE = "~~~ Welcome to TWU Biblioteka! ~~~";
    public static final String INVALID_OPTION_ERROR = "The provided option number is not valid. Select a valid option!";
    public static final String EXIT_MESSAGE = "Thank you for using TWU Biblioteka\n      Have a pleasant day!";
    public static final String COLUMN_SEPARATOR = " | ";

    public static void printStringWithCarriageReturn(String stringToPrint)
    {
        System.out.println(stringToPrint);
    }

    public static void printString(String message) { System.out.print(message); }

    public static void printStringWithEmptyLine( String stringToPrint )
    {
        System.out.println(stringToPrint);
        System.out.println();
    }

    private static void printFirstThreeCols(String firstCol, int firstColLength, String secondCol, int secondColLength, String thirdCol)
    {
        System.out.print(generateStringWithGivenLength(firstCol, firstColLength) + COLUMN_SEPARATOR);
        System.out.print( generateStringWithGivenLength(secondCol, secondColLength) +  COLUMN_SEPARATOR);
        System.out.print( thirdCol );
    }

    public static void printRowWithThreeColumns(String firstCol, int firstColLength, String secondCol, int secondColLength, String thirdCol)
    {
        printFirstThreeCols(firstCol, firstColLength, secondCol, secondColLength, thirdCol);
        System.out.println();
    }

    public static void printRowWithFourColumns(String firstCol, int firstColLength,
                                               String secondCol, int secondColLength,
                                               String thirdCol, String fourthCol)
    {
        printFirstThreeCols(firstCol, firstColLength, secondCol, secondColLength, thirdCol);
        System.out.println( COLUMN_SEPARATOR + fourthCol );
    }

    public static String generateStringWithGivenLength(String actualString, int finalStringLength)
    {
        String result = actualString;
        for( int i = 0; i < (finalStringLength - actualString.length()); i++)
        {
            result += " ";
        }
        return result;
    }

    public static void printWelcomeMessage()
    {
        printStringWithCarriageReturn(WELCOME_MESSAGE);
    }

    public static void printInvalidOptionErrorMessage()
    {
        printStringWithEmptyLine( INVALID_OPTION_ERROR);
    }

    public static void printExitMessage()
    {
        printStringWithCarriageReturn("");
        printStringWithCarriageReturn(EXIT_MESSAGE);
    }
}
